import { ElMessage } from "element-plus"
import { MyElForm } from "../interface"
import type { ValidateFieldsError } from 'async-validator'
/**
 * 报错并滚动
 * @param rule Elform 组件
 * @param invalidFields 认证规则
 */
export function validate(rule: MyElForm, invalidFields: ValidateFieldsError, isscroll = true) {
    const porp = Object.keys(invalidFields).pop()
    const msg = Object.values(invalidFields).pop()
    if (porp && isscroll) {
        rule.scrollToField(porp)
    }
    if (msg) {
        ElMessage.error(msg.pop()?.message)
    }
}